package com.example.aixiangshou.runninggame;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.x_memteor.base_master.application.MyApplication;
import com.x_memteor.base_master.base.BaseActivity;
import com.x_memteor.base_master.bean.GameBean;
import com.x_memteor.base_master.bean.ItemBean;
import com.x_memteor.base_master.utils.RecycleViewUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class ChooseOptionActivity extends BaseActivity {

    @BindView(R.id.recy_icon)
    RecyclerView recyIcon;

    List<IconBean> iconBeanList;
    IconAdapter iconAdapter;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.btnCountTimer)
    Button btnCountTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initRootView() {
        setContentView(R.layout.activity_choose_option);
    }

    @Override
    public void initView() {
        RecycleViewUtils.getGridLayoutManager(ChooseOptionActivity.this, recyIcon, 2);
    }

    @Override
    public void initData() {
        iconBeanList = new ArrayList<>();
        if (MyApplication.getInstance().getGameBean().getList() != null) {
            for (ItemBean itemBean : MyApplication.getInstance().getGameBean().getList()) {
                iconBeanList.add(new IconBean(itemBean.getIcon()));
            }
        }
        iconAdapter = new IconAdapter(R.layout.item_icon, iconBeanList);
        recyIcon.setAdapter(iconAdapter);

        //倒计时总时间为10S，时间防止从9s开始显示
        MyCountTimer myCountTimer = new MyCountTimer(4000, 1000, btnCountTimer, "GO!");
        myCountTimer.start();

        myCountTimer.setOnFinishListener(new MyCountTimer.OnFinishListener() {
            @Override
            public void onFinish() {
                if (MyApplication.getInstance().getGameBean().getGameType() == GameBean.GAME_TYPE_ROULETTE) {
                    startActivity(new Intent(ChooseOptionActivity.this, LuckPanActivity.class));
                } else {
                    startActivity(new Intent(ChooseOptionActivity.this, NombreActivity.class));
                }
                finish();
            }
        });
    }

    @Override
    public void initListener() {
        iconAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                if (MyApplication.getInstance().getGameBean().getGameType() == GameBean.GAME_TYPE_ROULETTE) {
                    startActivity(new Intent(ChooseOptionActivity.this, LuckPanActivity.class));
                } else {
                    startActivity(new Intent(ChooseOptionActivity.this, NombreActivity.class));
                }
            }
        });
    }
}
